home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / rayshade / graphtal.lzh / Graphtal.Amiga / ValueStack.h < prev    next >
C/C++ Source or Header  |  1992-11-17  |  1KB  |  65 lines

  1. /*
  2.  * ValueStack.h  - class definitions for fast value stack.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #ifndef ValueStack_H
  20. # define ValueStack_H
  21.  
  22. #include "Value.h"
  23. #include "Error.h"
  24.  
  25. //___________________________________________________________ ValueStack
  26.  
  27. static const int STACK_SIZE = 10; 
  28.  
  29. class ValueStack
  30. {
  31. public:
  32.   ValueStack();
  33.   ~ValueStack();
  34.  
  35.   void clear();
  36.   Value& pop();
  37.   void push(const Value& v);
  38.   
  39. private:
  40.   Value items[STACK_SIZE];
  41.   int sp;
  42. };
  43.  
  44. inline void ValueStack::clear()
  45. {
  46.   sp = -1;
  47. }
  48.  
  49. inline void ValueStack::push(const Value& v)
  50. {
  51.   if (sp >= STACK_SIZE)
  52.     Error(ERR_ABORT, "ValueStack::push stack is full");
  53.   items[++sp] = v; 
  54. }
  55.  
  56. inline Value& ValueStack::pop()
  57. {
  58.   if (sp < 0)
  59.     Error(ERR_ABORT, "ValueStack::pop stack is empty");
  60.   return items[sp--];
  61. }
  62.  
  63.  
  64. #endif // ValueStack_H
  65.